package com.miao.mapper;

import com.miao.pojo.MediaProcess;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-02-03
 */
@Mapper
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {

    //当前分片根据index获取任务
    //"select * from media_process t where  t.id % #{shardTotal} = #{shardIndex} and (t.status=1 or t.status=3) and t.fail_count<3 limit #{count}"
    @Select("select * from media_process t where t.id % #{sharedTotal} = #{sharedIndex} and (t.status=1 or t.status = 3) and t.fail_count < 3 limit #{count}")
    public List<MediaProcess> getListOfProcessOfXll(@Param("sharedTotal") int sharedTotal, @Param("sharedIndex") int sharedIndex, @Param("count") int count);

    //开启一个任务，锁
    @Update("update media_process m set m.status='4' where (m.status='3' or m.status='1') and m.fail_count<3 and m.id=#{id}")
    public int startTask(Long id);
}
